package com.peng.controller;

import com.peng.mapper.UserMapper;
import com.peng.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class IndexController {
    @Autowired
    private UserMapper userMapper;

    @GetMapping({"/", "/index"})
    public String toIndex() {
        return "index";
    }

    @PostMapping("/failure")
    @ResponseBody
    public String failure(){
        return "账号或者密码不对";
    }
    //首页身体
    @GetMapping("/main")
    public String toMain() {
        return "main";
    }

    //首页链接
    @GetMapping("/footer")
    public String toFooter() {
        return "footer";
    }

    //托福人首页
    @GetMapping("/toefl-people/index")
    public String toToeflPeople_Index() {
        return "toefl-people/index";
    }

    //公开课首页
    @GetMapping("/open-course/main")
    public String to0penCourse_main() {
        return "open-course/main";
    }

    //群组聊首页
    @GetMapping("/group-chat/groupchat-groupchat")
    public String toGroupChat_groupchat_groupchat() {
        return "group-chat/groupchat-groupchat";
    }

    //福利城堡首页
    @GetMapping("/welfare-castle/index")
    public String toWelfareCastle_index() {
        return "welfare-castle/index";
    }

    //个人中心
    @GetMapping("/personal-data/user-index")
    public String toPersonal_data_user_index() {
        return "personal-data/user-index";
    }

    //登录界面
    @GetMapping("/login")
    public String toLogin_register_login() {
        return "login-register/login";
    }

    //注册页面
    @GetMapping("/register")
    public String tologinRegister_register() {
        return "login-register/register";
    }

    //托福分类
    @GetMapping("/toefl-people/toefl-type")
    public String toToefl_type() {
        return "toefl-people/toefl-type";
    }

    //托福详情
    @GetMapping("/toefl-people/toefl-details")
    public String toToefl_peopleToefl_details() {
        return "toefl-people/toefl-details";
    }

    //福利城堡详情
    @GetMapping("/welfare-castle/welfareCastle-details")
    public String toWelfareCastle_details() {
        return "welfare-castle/welfareCastle-details";
    }

    //福利城堡发布
    @GetMapping("/welfare-castle/welfareCastle-publish")
    public String toWelfareCastle_publish() {
        return "welfare-castle/welfareCastle-publish";
    }

    @GetMapping("/getUser")
    @ResponseBody
    public User user(Authentication authentication){
        return userMapper.selectUserByUserName(authentication.getName());
    }
}
